﻿using Drive.DbAccess;
using Drive.LiveExcelHost.Models;
using Drive.LiveExcelHost.Services;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Drive.LiveExcelHost.Controllers
{
    public class SpreadsheetController : HttpService
    {
        [Path("*")]
        public void HandleRequest()
        {
            var id = Request.Path.Split('/').Last();
            if (!string.IsNullOrEmpty(id))
            {
                var spreadsheets = ExcelService.spreadsheets;
                if (this.Request.Method == "GET")
                {
                    var fileName = id;
                    var spreadsheet = ExcelService.LoadSpreadsheet(fileName);
                    this.Response.WriteString(JsonConvert.SerializeObject(spreadsheet, Formatting.None));
                }
                else
                {
                    var content = "{\"success\":1,\"message\":\"假装操作成功\"}";
                    this.Response.Headers.Add("Content-Type", "application/json");
                    this.Response.WriteString(content);
                }
            }
        }
    }
}
